import { Body, JsonController, Post, Get, Param, NotFoundError, Put } from 'routing-controllers'
import { Inject, Service } from 'typedi'
import { BasePageResponseDto, BaseSingleResponseDto } from '@/dtos/BaseDto';
import { RoleService } from '../services/RoleService';
import { CreateRoleDto, RoleDto, UpdateRoleDto } from '../dtos/RoleDto';

@Service()
@JsonController('/role')
export class RoleController {

  @Inject()
  private roleService!: RoleService;

  @Get('/')
  public async getRoles(): Promise<BasePageResponseDto<RoleDto>> {
    return this.roleService.findAll();
  }

  @Get('/:id')
  public async getRoleById(@Param('id') roleId: number): Promise<BaseSingleResponseDto<RoleDto>> {
    return this.roleService.get(roleId);
  }

  @Post('/')
  public async createRole(@Body() role: CreateRoleDto): Promise<BaseSingleResponseDto<RoleDto>> {
    return this.roleService.create(role);
  }

  @Put('/')
  public async updateRole(@Body() role: UpdateRoleDto): Promise<BaseSingleResponseDto<RoleDto>> {
    return this.roleService.update(role);
  }

  @Post('/batch-delete')
  public async batchDelete(@Body() roleIds: Array<number>): Promise<BaseSingleResponseDto<boolean>> {
    return this.roleService.batchDelete(roleIds);
  }

}
